﻿using LxBasic;

namespace LxCore.Samples
{
    public class SolidCuboidTransientConduction : SampleVMBase
    {
        public SolidCuboidTransientConduction() : base()
        {
            Name = "长方体瞬态导热";
            FileName = "Case0-Chang.msh";
        }
        public override void RunCase()
        {
            //create physical model
            LxSim.Sim.Physics.TimeDiscreteType = TimeDiscreteTypes.Explicit_2nd;
            LxSim.Sim.Physics.TimeInterval = new ConstField.Double(1);
            var physical = LxSim.Sim.Physics.CreatePhysicalModel();
            physical.PhysicalType = PhysicalTypes.固体;
            physical.IsEnergyEnabled = true;
            physical.MaterialProperty.Density = ConstField.Double1;
            physical.MaterialProperty.SpecificHeat = ConstField.Double1;

            //set zone condition
            var z = FindZone("BODY");
            var zcond = ResHelper.GetCond(z);
            zcond.PhysicalModel = physical;
            zcond.EnergySource_b = new ConstField.Double(1);
            

            var t_IN = FindBound(z, "IN");
            //var tinset = ResHelper.GetCond(t_IN);
            //tinset.WallThermalType = WallThermalTypes.定热流密度;

            var t_OUT = FindBound(z, "OUT");
            //var toutset = ResHelper.GetCond(t_OUT);
            //toutset.WallThermalType = WallThermalTypes.定壁温;
            //toutset.Temperature = new ConstField.Double(300);

            var t_around = FindBound(z, "AROUND");
            //set monitor
            var monitor = LxSim.Sim.Monitors.CreateMonitor("平均温度_Ite", StatisticTypes.VolumnAverage);
            monitor.ScalarType = ScalarFieldTypes.Temperature;
            monitor.SetSelector(z.Inner, true);
            var monitor2 = LxSim.Sim.Monitors.CreateMonitor("平均温度_Time", StatisticTypes.VolumnAverage);
            monitor2.ScalarType = ScalarFieldTypes.Temperature;
            monitor2.SetSelector(z.Inner, true);
            monitor2.MonitorTrigerType = MonitorTrigerTypes.TimeStep;
            //
            var graph = LxSim.Sim.Visuals.CreateGraph("边界温度");
            graph.GraphType = GraphTypes.等值图;
            graph.ScalarType = ScalarFieldTypes.Temperature;
            graph.SetSelector(t_IN, true);
            graph.SetSelector(t_OUT, true);
            graph.SetSelector(t_around, true);

            //run computation
            LxSim.Sim.Steps.IterationStep.MaxStepRule.MaxStep = 20;
            LxSim.Sim.Steps.TimeStep.MaxStepRule = null;
            LxSim.Sim.Steps.TimeStep.MaxTimeRule.MaxTime = 10;
            MultiThreads.SetThreadsCount(1);
            //LxSim.Sim.SolveCenter.TemperatureGroup.SolverType = LxLESS.IterationTypes.Jacobi;
            //加载到界面
            RunSimulation();
        }
    }
}
